package com.esun.cheetah.biz.personal.lotteryrecord;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;

import com.esun.cheetah.biz.personal.personalinfo.UserInfo;
import com.esun.cheetah.config.BizCode;
import com.esun.cheetah.config.Key;
import com.esun.cheetah.model.personal.LotteryRecordsBean;
import com.esun.cheetah.network.AbsInferiorityCommunicater;
import com.esun.util.log.EDebug;

/**
 * 
 * @Package 
 *          com.esun.cheetah.biz.personal.lotteryrecord.GetLotteryRecordListCommunicater
 * @ClassName: GetLotteryRecordListCommunicater
 * @Description: TODO(获取解析 投注列表的Json)
 * @author 孔祥攀 <br/>
 * @date 2012-3-29 下午2:16:52
 * 
 */
public class GetLotteryRecordListCommunicater extends
		AbsInferiorityCommunicater {

	private String lotid;
	private String seltype;
	private String time;
	private int pageno;

	private ArrayList<LotteryRecordsBean> lotteryRecordsList;

	public GetLotteryRecordListCommunicater(Handler handler, String lotid,
			String seltype, int pageno, String time) {
		super(handler);
		this.lotid = lotid;
		this.seltype = seltype;
		this.pageno = pageno;
		this.time = time;

		lotteryRecordsList = new ArrayList<LotteryRecordsBean>();
	}

	@Override
	public HashMap<String, String> comHashMap() {
		HashMap<String, String> hmJson = new HashMap<String, String>();
		hmJson.put(Key.KEY_ID, BizCode.BIZCODE_LotteryRecord_LIST);
		hmJson.put(Key.KEY_SELTYPE, seltype);
		hmJson.put(Key.KEY_LOTID, lotid);
		hmJson.put(Key.KEY_PAGESIZE, "10");
		hmJson.put(Key.KEY_TIME, time);
		hmJson.put(Key.KEY_PAGENO, String.valueOf(pageno));
		hmJson.put(Key.KEY_CK, UserInfo.getUserInfo().getCk());

		return hmJson;
	}

	/**
	 * @throws JSONException
	 * @Title: getJsonContent
	 * @Description: 解析json
	 * @param
	 * @return Object
	 * @throws
	 */
	@Override
	public void getJsonContent(String serverRes) throws JSONException {

		JSONObject jsonObject = new JSONObject(serverRes);

		if (!jsonObject.isNull(Key.KEY_DATA)) {
			jsonObject = jsonObject.getJSONObject(Key.KEY_DATA);
			JSONArray artr = jsonObject.getJSONArray("array");

			for (int i = 0; i < artr.length(); i++) {
				JSONObject localJs = artr.optJSONObject(i);
				if (localJs != null) {
					LotteryRecordsBean lotteryRecordsBean = new LotteryRecordsBean();
					EDebug.o("tongxinkaishi ");
					lotteryRecordsBean.lotname = localJs
							.getString(Key.KEY_LOTNAMEXX); // 彩种名称
					lotteryRecordsBean.expect = localJs
							.getString(Key.KEY_EXPECT); // 期号
					lotteryRecordsBean.playname = localJs
							.getString(Key.KEY_PLAYNAME);// 玩法名称
					lotteryRecordsBean.addtime = localJs
							.getString(Key.KEY_ADDTIME);// 方案发起时间、下注时间
					lotteryRecordsBean.paymoney = localJs
							.getString(Key.KEY_PAYMONEY);// 投注金额、认购金额
					lotteryRecordsBean.renqi = localJs.getString(Key.KEY_RENQI);// 人气
					lotteryRecordsBean.isjprize = localJs
							.getString(Key.KEY_ISJPRIZE);// 0未，1已 开奖
					lotteryRecordsBean.issuc = localJs.getString(Key.KEY_ISSUC);// 0未，1已
																				// 出票
					lotteryRecordsBean.getmoney = localJs
							.getString(Key.KEY_GETMONEY);// 获奖金额
					lotteryRecordsBean.playid = localJs
							.getString(Key.KEY_WTYPE); // 玩法id
					lotteryRecordsBean.fausername = localJs
							.getString(Key.KEY_FAUSERNAME);// 发起人
					lotteryRecordsBean.proid = localJs.getString(Key.KEY_PROID);// 方案编号
					lotteryRecordsBean.isHeMai = localJs
							.getString(Key.KEY_ISHM);
					lotteryRecordsBean.uid = localJs.getString(Key.KEY_UID);// 认购id
					lotteryRecordsBean.opencode = localJs
							.getString(Key.KEY_OPENCODE);// 开奖号码
					lotteryRecordsBean.id = localJs.getString(Key.KEY_ID);
					lotteryRecordsBean.isjprize = localJs
							.getString(Key.KEY_ISJPRIZE);// 算奖
					lotteryRecordsBean.isprize = localJs
							.getString(Key.KEY_ISPRIZE);// 派奖
					lotteryRecordsList.add(lotteryRecordsBean);
				}
			}
		}

	}

	public ArrayList<LotteryRecordsBean> getLotteryRecordsList() {
		return this.lotteryRecordsList;
	}

	public void setLotteryRecordsList(
			ArrayList<LotteryRecordsBean> lotteryRecordsList) {
		this.lotteryRecordsList = lotteryRecordsList;
	}

}
